﻿using System;
using System.Collections.Generic;
using System.Text;
using DailyDiet.Models;
using DailyDiet.Services;
using DailyDiet.Services.Constant;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace DailyDiet.ViewModels
{
    public class TasteSetViewModel : ViewModelBase {
        private IPreferenceStorage _preference;

        public TasteSetViewModel(IPreferenceStorage preferenceStorage) {
            _preference = preferenceStorage;
        }

        

        private int _spicyIndex;

        public int SpicyIndex {
            get => _spicyIndex;
            set => Set(nameof(SpicyIndex), ref _spicyIndex, value);
        }

        private int _sweetIndex;

        public int SweetIndex {
            get => _sweetIndex;
            set => Set(nameof(SweetIndex), ref _sweetIndex, value);
        }

        private int _healthIndex;

        public int HealthIndex {
            get => _healthIndex;
            set => Set(nameof(HealthIndex), ref _healthIndex, value);
        }

        private int _tastyIndex;

        public int TestyIndex {
            get => _tastyIndex;
            set => Set(nameof(TestyIndex), ref _tastyIndex, value);
        }


        private RelayCommand _saveCommand;

        public RelayCommand SaveCommand =>
            _saveCommand ?? (_saveCommand =
                new RelayCommand(() => SaveCommandFunc()));

        public void SaveCommandFunc() {
            _preference.Set(TasteSetConstant.SpicyIndexKey,TestyIndex);
            _preference.Set(TasteSetConstant.HealthIndexKey, HealthIndex);
            _preference.Set(TasteSetConstant.SweetIndexKey, SweetIndex);
            _preference.Set(TasteSetConstant.TasteIndexKey,TestyIndex);
        }

        private RelayCommand _appearingCommand;

        public RelayCommand AppearingCommand =>
            _appearingCommand ?? (_appearingCommand =
                new RelayCommand((() => AppearingCommandFunc())));

        public void AppearingCommandFunc() {
            SpicyIndex = _preference.Get(TasteSetConstant.SpicyIndexKey,TasteSetConstant.DefaultIndex);
            SweetIndex = _preference.Get(TasteSetConstant.SweetIndexKey,TasteSetConstant.DefaultIndex);
            HealthIndex = _preference.Get(TasteSetConstant.HealthIndexKey, TasteSetConstant.DefaultIndex);
            TestyIndex = _preference.Get(TasteSetConstant.TasteIndexKey, TasteSetConstant.DefaultIndex);
        }
    }
}
